/*   **********************************************************************  **
 **   Copyright notice                                                       **
 **                                                                          **
 **   (c) 2009, Around(J2)ME				                                 **
 **   All rights reserved.                                                   **
 **                                                                          **
 **   This program and the accompanying materials are made available under   **
 **   the terms of the New BSD License which accompanies this    			 **
 **   distribution.											                 **
 **   A copy is found in the textfile LICENSE.txt							 **
 **                                                                          **
 **   This copyright notice MUST APPEAR in all copies of the file!           **
 **                                                                          **
 **   Main developers:                                                       **
 **     Juri Strumpflohner		http://blog.js-development.com	             **
 **		Matthias Braunhofer		http://matthias.jimdo.com                    **
 **                                                                          **
 **  **********************************************************************  */

package com.aroundj2me.unittests.tests;

import j2meunit.framework.Test;
import j2meunit.framework.TestCase;
import j2meunit.framework.TestMethod;
import j2meunit.framework.TestSuite;
import java.io.IOException;
import com.aroundj2me.utility.StringUtils;

public class StringUtilsTest extends TestCase {
	
	public StringUtilsTest() {
	}
	
	public StringUtilsTest(String name, TestMethod method) {
		super(name, method);
	}
	
	protected void setUp() throws Exception {
	}
	
	protected void tearDown() throws Exception {
	}
	
	public void testReplace() {
		String string = "&test";
		String replaceString = "&";
		String replaceWith = "&amp;";
		String expected = "&amp;test";
		
		assertEquals("Outcome should be equals as expected", expected, StringUtils.replace(string, replaceString, replaceWith));
	}
	
	public void testSplit(){
		String myTestString = "Hi,there";
		
		String[] splitted = StringUtils.split(myTestString, ',');
		assertEquals("Hi", splitted[0]);
		assertEquals("there", splitted[1]);
	}
	
	public Test suite() {
		TestSuite aSuite = new TestSuite();
		aSuite.addTest(new StringUtilsTest("StringUtilsTest:testReplace", new TestMethod() { 
			public void run(TestCase tc) throws IOException {
				((StringUtilsTest) tc).testReplace(); 
			} 
		}));
		aSuite.addTest(new StringUtilsTest("StringUtilsTest:testSplit", new TestMethod() { 
			public void run(TestCase tc) throws IOException {
				((StringUtilsTest) tc).testSplit(); 
			} 
		}));
		return aSuite;
	}
}
